package sessionBeans;

import java.util.List;

import javax.ejb.Stateful;

import com.sun.xml.ws.rx.rm.runtime.sequence.persistent.PersistenceException;

import saa.model.usuario.Aluno;
import dao.AlunoDao;

@Stateful
public class Autenticador implements AutenticadorImpl {
	
		private String session;			
		private String password;
		
		public Autenticador() {
			super();
		}
		
		public boolean logIn(String session , String password) {
			try{
				AlunoDao dao = new AlunoDao();
				List<Aluno> alunos = dao.getAlunos();			
				for (Aluno aluno : alunos) {
					if(aluno.getLogin().contentEquals(session))
					{
						if(aluno.getSenha().contentEquals(password)){
							this.session = session;
							this.password = password;
							return true;						
						}
					}
				}				
			}
			catch(javax.persistence.PersistenceException e){
			 	System.out.println(e.getMessage());
			}			
			return false;
		}
		
		public String getSession() {
			return session;
		}

		public String getPassword() {
			return password;
		}		
	
}
